home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / VERUSR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-15  |  2.7 KB  |  111 lines

  1. /*
  2. **  VERUSR.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program verifies an email user.
  5. **
  6. **  In order to verify a user, you must first connect to the 
  7. **  SMTP server containing the user. Some SMTP servers may
  8. **  refuse this information because of security concerns.
  9. **  Also, note that connecting to some SMTP servers can be
  10. **  very slow.
  11. **
  12. **  Also see the BCAST example program. 
  13. */
  14.  
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "see.h"
  19. #include "email.h"
  20.  
  21. #define QUOTE 0x22
  22.  
  23. static char Buffer[512];
  24.  
  25. static LPSTR UserPtr;
  26. static LPSTR DomainPtr;
  27.  
  28. /* display error message */
  29.  
  30. static void ShowError(int Code, LPSTR Msg)
  31. {printf("ERROR: ");
  32.  if(Msg) printf("%s\n",Msg);
  33.  if(Code)
  34.    {seeErrorText(Code,(LPSTR)Buffer,50);
  35.     printf("%s\n",(LPSTR)Buffer);
  36.    }
  37. }
  38.  
  39. void main(int argc, char *argv[])
  40. {int i, Code; 
  41.  int Version;
  42.  LPSTR Ptr;
  43.  
  44.  if(argc<2)
  45.    {printf("Usage: VERUSR user1 user2 ...\n");
  46.     printf("   eg: VERUSR msc@traveller.com lillian@ro.com\n");
  47.     exit(1);
  48.    } 
  49.  
  50.  /* display parameters */
  51.   
  52.  Version = seeStatistics(SEE_GET_VERSION);
  53.  printf("SEE4C Version %1x.%1x.%1x\n",0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
  54.  
  55.  /* define diagnostics log file */
  56.  ///seeStringParam(SEE_LOG_FILE, (LPSTR)"verusr.log");
  57.  
  58.  for(i=1;i<argc;i++)
  59.    {printf("%2d: ",i);
  60.     if(strchr(argv[i],'<')) strcpy(Buffer,argv[i]);
  61.     else
  62.       {/* add '<>' brackets */
  63.        strcpy(Buffer, "<");
  64.        strcat(Buffer, argv[i]);
  65.        strcat(Buffer, ">");
  66.       }
  67.     Code = seeVerifyFormat((LPSTR)Buffer);
  68.     if(Code<0) 
  69.       {printf("Improper format [%s].\n",Buffer);
  70.        continue;
  71.       }
  72.  
  73.     Ptr = strchr(Buffer,'@');
  74.     if(Ptr)
  75.       {*Ptr = '\0';
  76.        UserPtr = &Buffer[1];
  77.        DomainPtr = Ptr + 1;
  78.        Ptr = strchr(DomainPtr,'>');
  79.        if(Ptr) *Ptr = '\0';
  80.       }
  81.     else
  82.       {printf("ERROR in email address\n");
  83.        continue;
  84.       }
  85.  
  86.     /* connect to SMTP server */
  87.     printf("Connecting to %c%s%c ...",QUOTE,(LPSTR)DomainPtr,QUOTE);
  88.     Code = seeSmtpConnect(
  89.        (LPSTR)DomainPtr,           /* SMTP server */
  90.        (LPSTR)YOUR_EMAIL_ADDR,     /* return email address */ 
  91.        (LPSTR)NULL);               /* Reply-To header */
  92.     if(Code<0)
  93.        {ShowError(Code, "FAILS.\n"); 
  94.         continue;
  95.        }
  96.  
  97.     /* verify the user */
  98.     printf("OK. %c%s%c is ",QUOTE,(LPSTR)UserPtr,QUOTE);
  99.     Code = seeVerifyUser((LPSTR)UserPtr);
  100.     if(Code==0) 
  101.       {seeDebug(SEE_GET_LAST_RESPONSE, (LPSTR)Buffer, 128);
  102.        printf("NOT verified (%s).\n",Buffer);
  103.       }
  104.     else printf("verified.\n"); 
  105.     seeClose(); 
  106.    }
  107.  printf("Done.\n");
  108. } /* end main */
  109.  
  110.  
  111.